/*
 * @Descripttion: bindActionCreators模块
 * @Author: lukasavage
 * @Date: 2021-11-24 20:54:53
 * @LastEditors: lukasavage
 * @LastEditTime: 2021-11-24 22:16:24
 */

/**
 * 
 * @param {object} actionCreators 
 * @param {function} dispatch 
 */
function bindActionCreators(actionCreators, dispatch) {
    const bindActionCreators = {};
    for (const i in actionCreators) {
        bindActionCreators[i] = function() {
            dispatch(actionCreators[i]())
        }
    }

    return bindActionCreators;
}

export default bindActionCreators;

// bindActionCreators需要做的事情：

/*
    ↓↓↓传入得actionCreators

    const actionCreators = {
        add() {
            return { type: 'ADD' }
        },
        del() {
            return { type: 'DEL' }
        }
    }
    
    ↓↓↓需要变成下面的形式

    const bindActions = {
        add() {
            return dispatch(add());
        }
        del() {
            return dispatch(del());
        }
    }






*/